package com.sskj.ws.service.impl;

import com.sskj.ws.dto.SubscribeMessage;
import com.sskj.ws.factory.DeviceSubscriptionFactory;
import com.sskj.ws.service.IMessageService;
import jakarta.websocket.Session;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;

@Slf4j
@Service
public class SubscribeMessageService implements IMessageService<SubscribeMessage> {

    @Autowired
    private DeviceSubscriptionFactory deviceSubscriptionFactory;

    @Override
    public String getSupportedType() {
        return "subscribe";
    }

    @Override
    public Class<SubscribeMessage> getMessageClass() {
        return SubscribeMessage.class;
    }

    @Override
    public void handle(SubscribeMessage message, Session session) {
        List<String> deviceCodes = message.getDeviceCodes();
        if (deviceCodes != null && !deviceCodes.isEmpty()) {
            deviceSubscriptionFactory.batchSubscribe(session, deviceCodes);
        }
    }
}
